home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.sco.programmer,comp.lang.c
- Path: quest1.questconsult.com!jrm
- From: jrm@quest1.questconsult.com (John Moyer)
- Subject: Re: Storing 20 character numbers
- Message-ID: <DpEMIA.GDE@quest1.questconsult.com>
- Date: Fri, 5 Apr 1996 19:37:22 GMT
- References: <DpB3sz.J9n@idm.com>
- Organization: Quest Consultants Inc.
-
- In article <DpB3sz.J9n@idm.com> eck@idm.com (Eric Kurbat) writes:
- >Hello folks!
- > I've got a question that has probably been asked before, but I need
- >to ask it again... I apologize in advance for any redundancy.
- >
- > Anyway, the question is, how do you store a 20 character integer
- >number in a non-character variable in C without losing any of the digits?
- >I did a little bit of playing around and a long double loses precision after
- >about 16 digits. Does anyone have any ideas?
- >
- >Regards,
- >Eric
-
- Are you saying that you need to do arithmetic with integers greater than
- 64 bits? If so, you need a bignum arithmetic package. One was posted to
- one of the source code groups a few years ago. If you can not find it
- elsewhere, I could e-mail it to you.
-
- If you wish to do some assembly programming, Binary Coded Decimal is a
- good representation for this sort of thing with lots of special opcodes
- to support the arithmetic in Intel CPUs. Packed Binary Coded Decimal
- can store 2 decimal digits per byte.
-
- A single unpacked BCD digit may be added this way in C if a and b contain
- the digits to be added with the result in c and carry.
-
-
- unsigned char a, b, c;
- int carry;
-
- c = a+b;
- if ( c >= 10 )
- {
- c -= 10;
- carry = 1;
- }
-
- Then the carry needs to be added to the next most significant digit.
- There exists an opcode to do an integer add with carry that would
- avoid the if().
-
- I hope this helps.
-
- John
-
-
-
- >--
- >----------------------------------------------------------------------------
- > "A cow can't whinny and horse has no udder. | Eric Kurbat : eck@idm.com
- > Up is down and sideways is straight ahead!" | eck@wwa.com
- >----------------------------------------------------------------------------
-
-
- --
- John Moyer http://www.questconsult.com/~jrm/
- Quest Consultants Inc. (tm) jrm@questconsult.com KC5GSX
- P.O. Box 721387 (405) 329-7475
- Norman, Oklahoma 73070-8069, USA Fax: (405) 329-7734
-